<?php

/**
 * @author christian
 * @copyright 2011
 */

//echo "registrar ....";
//echo getcwd();
//echo basename(getcwd());



$ruta=$_SERVER['DOCUMENT_ROOT']."/viventura"."/MDTour";
include_once("$ruta/conf/CConfig.php");
include_once("$ruta/elements/head.tpl");
include_once("$ruta/MDTourGeneral/CTourTableDraw.php");
include_once("$ruta/star.php");
include_once("$ruta/view/CDrawMenuTour.php");
include_once("$ruta/MDTourGeneral/CTourEditDraw.php");
include_once("$ruta/MDTourGeneral/CDrawPageReg.php");


if (!isset($_GET['default'])) {$_GET['default'] = "NULL"; }
$default=$_GET['default'];

if (!isset($_GET['idOpe'])) {$_GET['idOpe'] = "NULL"; }
$idOpe=$_GET['idOpe'];

if (!isset($_POST['idPack'])) {$_POST['idPack'] = "NULL"; }
$idPack=$_POST['idPack'];

if($idPack=="NULL"){
    if (!isset($_GET['codigo'])) {$_GET['codigo'] = "NULL"; }
    $idPack=$_GET['codigo'];    
}

if (!isset($_POST['idTour'])) {$_POST['idTour'] = "NULL"; }
$idTour=$_POST['idTour'];

//if (!isset($_POST['type'])) {$_POST['type'] = "NULL"; $id=$_GET['codigo'];}
//if (!isset($_GET['codigo'])) {$_GET['codigo'] = "NULL"; $id=$_POST['type'];}




// Recibe parametro de SmallDefinePack


$items=array("Nuevo Tour"=>"CSmallDefinePack.php","Nuevo paquete"=>"CTourEdit.php?codigo=159&default=2","Ver paquetes"=>"/viventura/MDTour/","Otra"=>"g");

CDrawMenuTour::getInstance()->setMenu($items);
CDrawMenuTour::getInstance()->rigth_side_begin();
CDrawMenuTour::getInstance()->DrawDivAdBegin("content_area_user_title","1");echo "<h1>Registro de tour</h1>";
CDrawMenuTour::getInstance()->DrawDivAdEnd();

$maintable="pack_has_tour";
$mainfield="idPackTour";
//$table1="tour";
$subfield="TOUR_idTour";



$action="CRegistroTour.php";$name="formulario_registro";$method="post";$NAME="";
CTourEditDraw::getInstance()->DrawHead($action,$name,$method,$NAME);

////////hidden//////////
CTourEditDraw::getInstance()->HiddenValue($default,"default");
CTourEditDraw::getInstance()->HiddenValue($idPack,"idPack");


//////////////////////////////////////Definicion de parametros////////////////////////////////////////
if($default==1){
   
     $idTour = CTourEditDraw::getInstance()->getDefaultTour("pack_has_tour","PACK_idPack",$idPack,"TOUR_idTour");
     $idPackTour = CTourEditDraw::getInstance()->getDefaultTour("pack_has_tour","PACK_idPack",$idPack,"idPackTour");

        
     $query = "select NomPack from pack where idPack = $idPack";
     
     $result = CModelo::getInstance()->getData($query);
     
    foreach($result as $i=>$v)
    {
    $table = $v;
        foreach ($table as $r => $c)
        $NomPack = $c; 
    }
    
     $paquete = $NomPack. " (".$idPack.") ";
     
     CDrawPageReg::getInstance()->DrawReadOnly("idPackHead","Paquete base",$paquete);


    ////////////////////////////////Datos generales del tour//////////////////////////////////
    CTourEditDraw::getInstance()->DrawSection("Datos generales");
    $items = array("OriTour"=>"Origen","DestTour"=>"Destino");
    $val_items = array (":required",":required");
    CTourEditDraw::getInstance()->DrawTextFillBox("",$items, "Tour", "idTour", $idTour,$val_items);
  
  
     CTourEditDraw::getInstance()->DrawSection("Información general del nuevo tour");
      echo "<div id='dashboard_info'>";
              
     $items = array("NomPack"=>"Nombre del tour");
     $val_items = (":required");
     CTourEditDraw::getInstance()->DrawTextFillBox("",$items, "Pack", "idPack", $idPack,$val_items);
     
     CTourEditDraw::getInstance()->HiddenValue($idTour,"idTour");
     
     
     $date=array("Fecha de inicio","Fecha de terminación");
          
      echo "<rigth><h2>Duración del tour</h2><rigth>";
    

             CDrawPageReg::getInstance()->DateFromTo("Duración del tour",$date); //date (0/1) esta en parametros
     echo "</div></br>";
     
     echo "<rigth><h2>Datos del Tour Conductor</h2><rigth>";
     $campos = array("idGuide"=>"idGuide", "FirstNamGui"=>"FirstNamGui", " LastNamGui"=> "LastNamGui");
     
//     $maintable, $table,$campos,$NAME, $id, $idnomain, $size)
     echo "<div id='dashboard_info'>";     
     CTourEditDraw::getInstance()->DrawSelect("pack_has_tour_has_guidetc","guidetc",$campos,"Guía 1",$idPackTour,"guidetc_idGuide",1);
     CTourEditDraw::getInstance()->DrawSelect("pack_has_tour_has_guidetc","guidetc",$campos,"Guía 2",$idPackTour,"guidetc_idGuide",1);     
     echo "</div>";
     //CTourEditDraw::getInstance()->DrawSelect("guidetc", $campos, "Tour Conductor 2", "idGuide2");
    

         
     }
    
else{
   
    
        
    echo "Se han cargado los datos predeterminados del tour default del paquete ".$idPack;
    
      
    $items = array("NomPack"=>"Nombre del tour","CostPerOne"=>"Costo por una persona","CostPerTwo"=>"Costo por dos personas");
    $val= array(":required",":integer",":integer");
    //CTourEditDraw::getInstance()->DrawTextFillBox($items,$pack,$val);
    CTourEditDraw::getInstance()->DrawTextFillBox("",$items,"pack","idPack",$idPack,$val);
   
//    CTourEditDraw::getInstance()->HiddenValue($idTour,"idTour");
//    $date=array("DateBegTour"=>"Disponible desde ","DateEndTour"=>"Disponible hasta ");
    
    $field=array("idPack","IntComPack");
    CTourEditDraw::getInstance()->DrawAreaFill("Descripción del paquete","pack",$field,$idPack);
    
            
  }



////////Default tour para editar el paquete, default tour como plantilla para el nuevo paquete////////////
$idPackTour = CTourEditDraw::getInstance()->getDefaultTour("pack_has_tour","PACK_idPack",$idPack,"idPackTour"); //para el defaultour
CTourEditDraw::getInstance()->HiddenValue($idPackTour, "idPackTour");
//echo $idPackTour."/";
$idOfi = CTourEditDraw::getInstance()->getAnyId("pack","idPack",$idPack,"OFICINAS_idOfi");
$idOpe = CTourEditDraw::getInstance()->getAnyId("oficinas","idOfi",$idOfi,"OPERADOR_idOpe");
CTourEditDraw::getInstance()->HiddenValue($idOpe,"idOpe");




///////////////////////////////fechas ///////////////////////////



///////////////////////////////extensiones///////////////////////////////////////////
$campos=array('IdExt','NomExt');
CTourEditDraw::getInstance()->DrawMultipleSelect("pack_has_tour_has_extensiones","extensiones",$campos,"Extensiones",$idPackTour,"extensiones_idExt");


///////////////////////////////enlaces externos ///////////////////////////////////////////
if($default==1){
    
        
        
     //   $pasajeros = CConfig::getInstance()->rutalocal."/MDTourGeneral/MDPasajeros/MDPasajeros.php?codigo=$idPackTour";
     //   CTourEditDraw::getInstance()->DrawButton("Registrar pasajeros",$pasajeros);
        
        
        
     //   $hoteles = CConfig::getInstance()->rutalogica."/MDHoteles/index.php?codigo=$idPackTour";
     //   CTourEditDraw::getInstance()->DrawButton("Modificar hoteles",$hoteles);
                                
    
        CTourEditDraw::getInstance()->DrawSubmmit("Registrar nuevo tour");
        
        }
        
else{
        //$url= CConfig::getInstance()->rutalogica."MD/MDEItinerary.php";
        //CTourEditDraw::getInstance()->DrawButton("Editar Default Tour","");
        echo "<div id='dashboard_info'>";
     //   CTourEditDraw::getInstance()->DrawTextFillBox("Fechas",$date, "pack_has_tour", "idPackTour", $idPackTour); //date (0/1) esta en parametros
        echo "</div>";
              
        $hoteles = CConfig::getInstance()->rutalogica."/MDHoteles/index.php?codigo=$idPackTour";
        
        CTourEditDraw::getInstance()->DrawTextFillBox("",$items, "Tour", "idTour", $idTour,$val_items);
   
        
        CTourEditDraw::getInstance()->DrawButton("Ver hoteles asignados",$hoteles);

        CTourEditDraw::getInstance()->DrawSubmmit("Actualizar paquete");
        
}


CDrawPageReg::getInstance()->DrawFoot();
CDrawMenuTour::getInstance()->rigth_side_end();

CDrawPageReg::getInstance()->DrawButton("Ver default tours","MDTourGeneral/index.php?default=1");
   
CDrawMenuTour::getInstance()->DrawDivAdEnd();


?>